package main.java.middle;

/**
 * @Author: 郑国荣
 * @Date: 2023-08-17-16:41
 * @Description:
 */
public class ReverseInt {
    public static int reverse(int x) {
        int INT_MAX = Integer.MAX_VALUE;
        int INT_MIN = Integer.MIN_VALUE;

        int reversed = 0;

        while (x != 0) {
            int digit = x % 10;

            if (reversed > INT_MAX / 10 || reversed < INT_MIN / 10) {
                return 0;
            }

            reversed = reversed * 10 + digit;
            x /= 10;
        }

        return reversed;
    }


    public static void main(String[] args) {
        int x=-112;
        System.out.println(reverse(x));
    }
}
